package sample.data;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import org.dreamwork.gson.GsonHelper;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2010-10-15
 * Time: 18:05:18
 */
public class Product implements Serializable {
    @Expose
    private int id;
    @Expose
    private String category;
    @Expose
    private String supplier;
    @Expose
    private String name;
    @Expose
    private String unit;
    @Expose
    private double store;
    @Expose
    private double price;

    public Product () {
    }

    public Product (String category, String supplier, String name, double price) {
        this.category = category;
        this.supplier = supplier;
        this.name = name;
        this.price = price;
    }

    public String getCategory () {
        return category;
    }

    public void setCategory (String category) {
        this.category = category;
    }

    public String getSupplier () {
        return supplier;
    }

    public void setSupplier (String supplier) {
        this.supplier = supplier;
    }

    public String getName () {
        return name;
    }

    public void setName (String name) {
        this.name = name;
    }

    public double getPrice () {
        return price;
    }

    public void setPrice (double price) {
        this.price = price;
    }

    public int getId () {
        return id;
    }

    public void setId (int id) {
        this.id = id;
    }

    public String getUnit () {
        return unit;
    }

    public void setUnit (String unit) {
        this.unit = unit;
    }

    public double getStore () {
        return store;
    }

    public void setStore (double store) {
        this.store = store;
    }

    @Override
    public String toString () {
        return "Product{" +
                "id=" + id +
                ", category='" + category + '\'' +
                ", supplier='" + supplier + '\'' +
                ", name='" + name + '\'' +
                ", unit='" + unit + '\'' +
                ", store=" + store +
                ", price=" + price +
                '}';
    }

    public static void main (String[] args) {
        Product p = new Product ("c1", "s1", "p1", 100);
        Gson g = GsonHelper.getGson ();
        String e = g.toJson (p);
        System.out.println (e);

        e = "{id:'1',name:'p1', price:'33'}";
        p = g.fromJson (e, Product.class);
        System.out.println (p);

        System.out.println (g.fromJson ("True", Boolean.class));
    }
}